package com.xuelang.pipeline.domain.pipeline.service.imp;

import com.xuelang.pipeline.client.common.exception.BizException;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.pipeline.dto.PipelineQuery;
import com.xuelang.pipeline.domain.pipeline.Pipeline;
import com.xuelang.pipeline.domain.pipeline.repository.PipelineRepository;
import com.xuelang.pipeline.domain.pipeline.service.PipelineDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 流水线领域服务实现类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Service
public class PipelineDomainServiceImpl implements PipelineDomainService {

    @Autowired
    private PipelineRepository pipelineRepository;

    @Override
    public PageRecord<Pipeline> pageList(long currentPage, long pageSize, PipelineQuery pipelineQuery) {
        return pipelineRepository.pageList(currentPage, pageSize, pipelineQuery);
    }

    @Override
    public List<Pipeline> list(PipelineQuery pipelineQuery) {
        return pipelineRepository.list(pipelineQuery);
    }


    @Override
    public Boolean save(Pipeline pipeline) {
        if(existsCode(pipeline.getCode())) {
            throw new BizException("流水线编码已经存在");
        }
        return pipelineRepository.save(pipeline);
    }

    @Override
    public Boolean update(Pipeline pipeline) {
        return pipelineRepository.update(pipeline);
    }

    @Override
    public Boolean delete(String code) {
        return pipelineRepository.delete(code);
    }

    @Override
    public Pipeline query(String code) {
        return pipelineRepository.query(code);
    }

    @Override
    public List<Pipeline> queryByComponentLabel(String componentLabel) {
        return pipelineRepository.queryByComponentLabel(componentLabel);
    }

    @Override
    public List<Pipeline> list(Pipeline pipeline) {
        return pipelineRepository.list(pipeline);
    }

    @Override
    public Boolean existsByEnvironmentUuid(String environmentUuid) {
        return pipelineRepository.existsByEnvironmentUuid(environmentUuid);
    }

    @Override
    public Boolean existsCode(String pipelineCode) {
        return pipelineRepository.existsCode(pipelineCode);
    }

    @Override
    public Boolean existsName(String pipelineCode, String pipelineName) {
        return pipelineRepository.existsName(pipelineCode, pipelineName);
    }
}
